<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="js/jquery-1.4.4.min.js"></script>
    <script src="js/jquery.ztree.all.min.js"></script>
    <link rel="stylesheet" href="zTreeStyle/zTreeStyle.css">
    <style>
        #tree{
            width: 500px;
            height: 500px;
            overflow: auto;
            border: 1px solid red;
            margin: 0 auto;
        }
    </style>
</head>
<body>

<ul class="ztree" id="tree">


</ul>

<button type="button" id="btn">改变当前icon</button>

<script>
    $(function (){

        let activeTreeNode = null;

        let $tree = $('#tree');
        let obj = [
            {
                "code": "1111",
                "name": "全部",
                "isLeaf": "1",
                "children": [
                    {
                        "code": "0fm7a-cfv7yg-028vp",
                        "name": "消防专家检查项",
                        "isLeaf": "1",
                        "isChecked": "0",
                        "children": [
                            {
                                "code": "0nw2q-js7rf0-00w6p",
                                "name": "A1建筑类别与耐火等级、总平面布局、 平面布置消防查验记录",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nw2q-pa7gf0-00qd7",
                                        "name": "2建筑类别与 耐火等级",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nw2q-qkevf0-00rqw",
                                                "name": "3建筑类别",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nw4b-yra0f0-00sfb",
                                "name": "A2建筑保温和外墙装饰、建筑内部装修消防查验记录",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nw4c-2e30f0-00g3b",
                                        "name": "2建筑保温及外墙装饰防火",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nw4c-42u8f0-00nve",
                                                "name": "3建筑外墙和屋面保温",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrh-y8wcf0-00g30",
                                "name": "测试分组3",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-0ng0f0-00593",
                                        "name": "测试分组3-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-3n7gf0-00udr",
                                                "name": "测试分组3-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-0favf0-00epy",
                                "name": "测试分组4",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-62pmf0-00gpv",
                                        "name": "测试分组4-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-s898f0-00vv8",
                                                "name": "测试分组4-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-1hecf0-00st5",
                                "name": "测试分组5",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-pjacf0-00pt2",
                                        "name": "测试分组5-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-r1w0f0-00x0j",
                                                "name": "测试分组5-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-5e9vf0-00nky",
                                "name": "测试分组6",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-tfavf0-00kyn",
                                        "name": "测试分组6-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-umrgf0-002v3",
                                                "name": "测试分组6-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-6apgf0-003mb",
                                "name": "测试分组7",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-vt5rf0-00u9y",
                                        "name": "测试分组7-1-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-x274f0-007ms",
                                                "name": "测试分组7-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-76jmf0-00s26",
                                "name": "测试分组8",
                                "isLeaf": "0",
                                "isChecked": "0"
                            },
                            {
                                "code": "0nxrj-8agrf0-00cbm",
                                "name": "测试分组9",
                                "isLeaf": "0",
                                "isChecked": "0"
                            },
                            {
                                "code": "0nxrj-99rcf0-00xg3",
                                "name": "测试分组10",
                                "isLeaf": "0",
                                "isChecked": "0"
                            },
                            {
                                "code": "0p1b0-xp3vf0-00st6",
                                "name": "测试A类",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0p1b1-gh84f0-00k7c",
                                        "name": "测试A-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0p1b1-je3rf0-00339",
                                                "name": "测试AAAA",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "code": "2222",
                "name": "全部22",
                "isLeaf": "1",
                "children": [
                    {
                        "code": "0fm7a-cfv7yg-028vp",
                        "name": "消防专家检查项",
                        "isLeaf": "1",
                        "isChecked": "0",
                        "children": [
                            {
                                "code": "0nw2q-js7rf0-00w6p",
                                "name": "A1建筑类别与耐火等级、总平面布局、 平面布置消防查验记录",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nw2q-pa7gf0-00qd7",
                                        "name": "2建筑类别与 耐火等级",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nw2q-qkevf0-00rqw",
                                                "name": "3建筑类别",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nw4b-yra0f0-00sfb",
                                "name": "A2建筑保温和外墙装饰、建筑内部装修消防查验记录",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nw4c-2e30f0-00g3b",
                                        "name": "2建筑保温及外墙装饰防火",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nw4c-42u8f0-00nve",
                                                "name": "3建筑外墙和屋面保温",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrh-y8wcf0-00g30",
                                "name": "测试分组3",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-0ng0f0-00593",
                                        "name": "测试分组3-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-3n7gf0-00udr",
                                                "name": "测试分组3-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-0favf0-00epy",
                                "name": "测试分组4",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-62pmf0-00gpv",
                                        "name": "测试分组4-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-s898f0-00vv8",
                                                "name": "测试分组4-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-1hecf0-00st5",
                                "name": "测试分组5",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-pjacf0-00pt2",
                                        "name": "测试分组5-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-r1w0f0-00x0j",
                                                "name": "测试分组5-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-5e9vf0-00nky",
                                "name": "测试分组6",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-tfavf0-00kyn",
                                        "name": "测试分组6-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-umrgf0-002v3",
                                                "name": "测试分组6-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-6apgf0-003mb",
                                "name": "测试分组7",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0nxrm-vt5rf0-00u9y",
                                        "name": "测试分组7-1-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0nxrm-x274f0-007ms",
                                                "name": "测试分组7-1-1",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "code": "0nxrj-76jmf0-00s26",
                                "name": "测试分组8",
                                "isLeaf": "0",
                                "isChecked": "0"
                            },
                            {
                                "code": "0nxrj-8agrf0-00cbm",
                                "name": "测试分组9",
                                "isLeaf": "0",
                                "isChecked": "0"
                            },
                            {
                                "code": "0nxrj-99rcf0-00xg3",
                                "name": "测试分组10",
                                "isLeaf": "0",
                                "isChecked": "0"
                            },
                            {
                                "code": "0p1b0-xp3vf0-00st6",
                                "name": "测试A类",
                                "isLeaf": "0",
                                "isChecked": "0",
                                "children": [
                                    {
                                        "code": "0p1b1-gh84f0-00k7c",
                                        "name": "测试A-1",
                                        "isLeaf": "0",
                                        "isChecked": "0",
                                        "children": [
                                            {
                                                "code": "0p1b1-je3rf0-00339",
                                                "name": "测试AAAA",
                                                "isLeaf": "1",
                                                "isChecked": "0"
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]

        let zTreeObj = $.fn.zTree.init($tree, {
            keep:{
                leaf: true,
                parent : true
            },
            data: {
                key: {
                    isParent: "isLeaf",
                    name: "name",
                    code: "code",
                    checked:'checked'
                },

            },
            view: {
                fontCss : function( treeId, treeNode){
                    return treeNode.isLeaf == '1' && treeNode.isChecked == "1" ? {"color":'#119106!important', 'font-weight': "600!important","padding-right": "20px!important","background":"url(/assets/images/common/cg.png) no-repeat 97% center",'background-size': '16px 16px'} : {};
                },
            },
            callback: {
                onClick:onClick,
            },
        }, obj);
        let treeObj = $.fn.zTree.getZTreeObj("tree");
        var nodes = treeObj.getNodes();

        var name = nodes[1].name;
        console.log(name);


        treeObj.copyNode(nodes[0], nodes[1], "inner");

        function onClick(e, treeId, treeNode){
            activeTreeNode = treeNode;
            console.log(treeNode);
        }


        $('#btn').click(function (){

        })





    })



</script>
</body>
</html>
